#include "IndexHTML.hpp"
#include "BackgroundDecoration.hpp"
#include "TableStyle.hpp"
#include "utilities.hpp" // for loadStylesheet()

#include <Wt/WApplication>
#include <Wt/WTextArea>
#include <Wt/WVBoxLayout>


webpages::IndexHTML::IndexHTML(Wt::WContainerWidget* parent)
    :
        Wt::WContainerWidget(parent)
{    
    /*
     * If/when it's time to bring the CSS back into the application (inline), the following can be used:
    */
    //Wt::WApplication::instance()->styleSheet().addRule(new webpages::resources::BackgroundDecoration);
    
    /*
     * Create the layout using CSS to decorate the "<div>" tags, created by instantiating
     * Wt::WContainerWidget(). (https://code.google.com/p/carblogger/wiki/GUI_webpages_layout)
    */
    Wt::WContainerWidget* table = new Wt::WContainerWidget(parent);
    table->setStyleClass("tablestyle");
    Wt::WApplication::instance()->styleSheet().addRule(new webpages::resources::TableStyle);
    
        
        Wt::WContainerWidget* left_cell = new Wt::WContainerWidget(table); // This is cell 0,0.
        left_cell->setStyleClass("left_cell_style");
        Wt::WApplication::instance()->styleSheet().addRule(new webpages::resources::LeftCellStyle);
        
        Wt::WVBoxLayout* left_cell_layout = new Wt::WVBoxLayout;
        left_cell_layout->setResizable(1);
        
        left_cell_layout->addWidget(new  Wt::WTextArea("Human-readable messages go here."));    
        

            //  Instantiate  a WindowBox
//                 Wt::WContainerWidget *gui_logwindow = new Wt::WContainerWidget();
//                 gui_logwindow->setStyleClass("gui_logwindow");
//                 
//                 Wt::WApplication::instance()->styleSheet().addRule(".gui_logwindow",
//                                                         "border-color: silver;"
//                                                         "border-width: thick;"
//                                                         "border-style: ridge;"
//                                                         "padding: 2px;"
// //                                                         "position: absolute;"
//                                                                   );
//                 gui_logwindow->resize(Wt::WLength::Auto, Wt::WLength::Auto);
            
//                 Wt::WTextArea* output_area = new Wt::WTextArea("Human-readable messages go here.");
//                 output_area->setStyleClass("output_area");
//                 Wt::WApplication::instance()->styleSheet().addRule(".output_area",
//                                                                    "min-height: 2%;"
// //                                                                    "max-height: 20%;"
//                                                                    "max-width: 99%;"
//                                                                    "min-width: 99%;"); 
                
//                 gui_logwindow->addWidget(output_area);
//             left_cell->addWidget(gui_logwindow);
        //         left_cell->addWidget(left_cell_layout); //TESTING
        
            
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~```````            
            
            
//             left_cell->addWidget(new Wt::WBreak());

            // Add bottom-left WindowBox
//             Wt::WContainerWidget *script_output_window = new Wt::WContainerWidget();
//             script_output_window->setStyleClass("script_output_window");
//             
//             Wt::WApplication::instance()->styleSheet().addRule(".script_output_window",
//                                                     "border-color: silver;"
//                                                     "border-width: thick;"
//                                                     "border-style: ridge;"
//                                                     "padding: 2px;"
//                                                     "position: absolute;"
// //                                                     "top: 200px;"
//                                                     "bottom: 1em;"                                                             
//             );
//         
//             Wt::WTextArea* output_area2 = new Wt::WTextArea("output from scripts go here.");
//             output_area2->setStyleClass("output_area2");
//             Wt::WApplication::instance()->styleSheet().addRule(".output_area2",
//                                                                 "min-height: 10%;"
//                                                                 "max-height: 60%;"
//                                                                 "max-width: 99%;"
//                                                                 "min-width: 99%;"); 
            
//             script_output_window->addWidget(output_area2);
//         left_cell->addWidget(script_output_window);

        // Separtate out the code 
        //         new webpages::windowboxes::DisplayModeSelectorViewport() //TESTING
        new webpages::windowboxes::DisplayModeSelectorViewport(table); // This is cell 0,1. Style defined in its ctor.
        
        //This is what the ControlButton did/was: 
        new components::ControlButton(table); // This is cell 1,1. Style defined in its ctor.
}


// webpages::IndexHTML::IndexHTML(Wt::WContainerWidget* parent)
//     :
//         Wt::WContainerWidget(parent)
// {    
//     /*
//      * If/when it's time to bring the CSS back into the application (inline), the following can be used:
//     */
//     //Wt::WApplication::instance()->styleSheet().addRule(new webpages::resources::BackgrdoundDecoration);
//     
//     /*
//      * Create the layout using CSS to decorate the "<div>" tags, created by instantiating
//      * Wt::WContainerWidget(). (https://code.google.com/p/carblogger/wiki/GUI_webpages_layout)
//     */
//     Wt::WContainerWidget* table = new Wt::WContainerWidget(parent);
//     table->setStyleClass("tablestyle");
//     Wt::WApplication::instance()->styleSheet().addRule(new webpages::resources::TableStyle);
//     
//         Wt::WVBoxLayout* left_cell = new Wt::WVBoxLayout(table);
//             left_cell->setResizable(1);
//         
// //         Wt::WContainerWidget* left_cell = new Wt::WContainerWidget(table); // This is cell 0,0.
// //         left_cell->setStyleClass("left_cell_style");
//         Wt::WApplication::instance()->styleSheet().addRule(new webpages::resources::LeftCellStyle);
// 
//             //  Instantiate  a WindowBox
//                 Wt::WContainerWidget *gui_logwindow = new Wt::WContainerWidget();
//                 gui_logwindow->setStyleClass("gui_logwindow");
//                 
//                 Wt::WApplication::instance()->styleSheet().addRule(".gui_logwindow",
//                                                         "border-color: silver;"
//                                                         "border-width: thick;"
//                                                         "border-style: ridge;"
//                                                         "padding: 2px;"
// //                                                         "position: absolute;"
//                                                                   );
//                 gui_logwindow->resize(Wt::WLength::Auto, Wt::WLength::Auto);
//             
//                 Wt::WTextArea* output_area = new Wt::WTextArea("Human-readable messages go here.");
//                 output_area->setStyleClass("output_area");
//                 Wt::WApplication::instance()->styleSheet().addRule(".output_area",
//                                                                    "min-height: 2%;"
// //                                                                    "max-height: 20%;"
//                                                                    "max-width: 99%;"
//                                                                    "min-width: 99%;"); 
//                 
//                 gui_logwindow->addWidget(output_area);
//                 
//             left_cell->addWidget(gui_logwindow);
// 
// //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~```````            
//             
//             
// //             left_cell->addWidget(new Wt::WBreak());
// 
//             // Add bottom-left WindowBox
//             Wt::WContainerWidget *script_output_window = new Wt::WContainerWidget();
//             script_output_window->setStyleClass("script_output_window");
//             
//             Wt::WApplication::instance()->styleSheet().addRule(".script_output_window",
//                                                     "border-color: silver;"
//                                                     "border-width: thick;"
//                                                     "border-style: ridge;"
//                                                     "padding: 2px;"
//                                                     "position: absolute;"
// //                                                     "top: 200px;"
//                                                     "bottom: 1em;"                                                             
//             );
//         
//             Wt::WTextArea* output_area2 = new Wt::WTextArea("output from scripts go here.");
//             output_area2->setStyleClass("output_area2");
//             Wt::WApplication::instance()->styleSheet().addRule(".output_area2",
//                                                                 "min-height: 10%;"
//                                                                 "max-height: 60%;"
//                                                                 "max-width: 99%;"
//                                                                 "min-width: 99%;"); 
//             
//             script_output_window->addWidget(output_area2);
//         left_cell->addWidget(script_output_window);
// 
//             
//         new webpages::windowboxes::DisplayModeSelectorViewport(table); // This is cell 0,1. Style defined in its ctor.
//         
//         //This is what the ControlButton did/was: 
//         new components::ControlButton(table); // This is cell 1,1. Style defined in its ctor.
// }